
#include "klib.h"

char *strbin(char *buffer, size_t size, unsigned int value)
{
	unsigned int n = sizeof(int) * 8;
	unsigned int i, x = 0;

	if (size < n + n / 4)
		return NULL;

	for (i = 0; i < n; i++) {
		if (i && (i % 4 == 0)) {
			buffer[x++] = ',';
		}
		if (value & (1 << (n - i - 1)))
			buffer[x++] = '1';
		else
			buffer[x++] = '0';
	}
	buffer[x] = '\0';
	return buffer;
}
